/*
 * Model.java
 *
 * Created on 22 de Julho de 2011, 11:53
 *
 */

package intopo.demonstrator.partnerclassification.gui;

import intopo.demonstrator.partnerclassification.Parameters;
import intopo.demonstrator.partnerclassification.Statistics;
import intopo.demonstrator.partnerclassification.State;
import intopo.demonstrator.partnerclassification.Partner;

import java.util.Vector;

/**
 * Model used by the components.
 * 
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 * @version 1.0 22 de Julho de 2011
 */
public class Model
{
	/**
	 * The parameters that the user has selected.
	 */
	static final Parameters parameters;
	/**
	 * The current state of the partner classification model.
	 */
	static State currentState;
	/**
	 * Statistics of the current run of the partner classification model.
	 */
	static Statistics statistics;
	/**
	 * State history of the partner classification model.
	 */
	static final Vector<State> history;
	/**
	 * Vector with candidate partners.
	 */
	static transient Partner[] partners;
	static
	{
		parameters = new Parameters ();
		history = new Vector<State> (1000, 1000);
		parametersChanged ();
	}
	/**
	 * Initialises data if the parameters have changed or a new run is to be performed.
	 */
	static void parametersChanged ()
	{
		Model.currentState = new State (Model.parameters);
		Model.statistics = new Statistics (Model.parameters);
		Model.history.clear ();
		Model.history.add (currentState);
		Model.partners = new Partner [Model.parameters.getPartners ().size ()];
		Model.parameters.getPartners ().toArray (Model.partners);
	}
	/**
	 * Performs a transition of the partner classification model.
	 */
	static void newTransition ()
	{
		State s = currentState.getTransition (statistics);
		currentState = s;
		history.add (currentState);
	}
	/**
	 * Indexed getter for property history.
	 * @param index Index of the property.
	 * @return Value of the property at <CODE>index</CODE>.
	 */
	static final State getHistory (int index)
	{
		return history.get (index);
	}
	/**
	 * This class is non instanciable.
	 */
	private Model ()
	{
	}
	
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
